package com.heima.msg.controller;

import com.alibaba.fastjson.JSON;
import com.heima.msg.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/sendMsg")
    public String sendMsg(){

        User user = new User();
        user.setId(1);
        user.setName("itcast");
        user.setAddr("成都");


        kafkaTemplate.send("topic-01", JSON.toJSONString(user));

        return "success";
    }
}
